// pages/softStep1/softStep1.js
const util = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    title: '',
    project_id:'',
    line1: '',
    line1Error: false,
    line1MinNum: 410,
    line1MaxNum: 440,
  },

  bindInput(e){
    this.setData({
      line1: e.detail.value
    });
    console.log(e.detail.value)
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if (options.title){
      this.setData({
        title: options.title
      })
      
    }
    if (options.project_id){
      this.setData({
        project_id: options.project_id
      }) 
    }
    console.log(this.data.project_id)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    var pid = this.data.project_id
    var docItemKey = 'pid_'+pid
    var stableDocData = wx.getStorageSync(docItemKey)
    if(stableDocData){
        var docJson = JSON.parse(stableDocData)
        if(docJson.step1Data!==undefined && docJson.step1Data!=null){
          this.setData({
            line1: docJson.step1Data
          })
        }
    }
  },

  onSave(event){
    console.log(this.data.line1)
    if(!util.checkInputNum('line1',this.data.line1,'简介',this.data.line1MinNum,this.data.line1MaxNum)){
      this.setData({
        line1Error: true
      })
      return;
    }

    this.setData({
      line1Error: false
    })
    var pid = this.data.project_id
    var itemKey = 'pid_'+pid
    var value = wx.getStorageSync(itemKey)
    var docJson = JSON.parse(value)
    docJson.step1Data = this.data.line1
    wx.setStorageSync(itemKey,JSON.stringify(docJson))
    wx.navigateBack()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})